home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1999 March
/
EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso
/
earcd
/
-archivi
/
-recent2
/
amhelios.lha
/
AmHelios
/
Amhelios.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1997-09-06
|
9KB
|
324 lines
/* -------------------------------------------------------------------------- *\
AMHELIOS.CPP
Copyright © 1997 by Jarno van der Linden
jarno@kcbbs.gen.nz
Radiosity renderer based on Helios. Original copyright notice:
// Author: Ian Ashdown, P.Eng.
// byHeart Software Limited
// 620 Ballantree Road
// West Vancouver, B.C.
// Canada V7S 1W3
// Tel. (604) 922-6148
// Fax. (604) 987-7621
//
// Copyright 1994-1996 byHeart Software Limited
//
// The following source code has been derived from:
//
// Ashdown, I. 1994. Radiosity: A Programmer's
// Perspective. New York, NY: John Wiley & Sons.
//
// It may be freely copied, redistributed, and/or modified
// for personal use ONLY, as long as the copyright notice
// is included with all source code files.
02 Aug 1997: Started GUI
\* -------------------------------------------------------------------------- */
/*
mkmk target=Amhelios force Amhelios.cpp error.cpp parse.cpp ff_clip.cpp ct_delta.cpp hc_scan.cpp ff_scan.cpp ct_scan.cpp patch3.cpp hc_delta.cpp environ.cpp ct_clip.cpp cubic_t.cpp prog_rad.cpp rad_eqn.cpp syn_cam.cpp bitmap24.cpp p_render.cpp c_jitter.cpp view_sys.cpp gamma.cpp p_clip4.cpp vector3.cpp MUIpreview.cpp CalcSub.cpp
*/
/* -------------------------------- Includes -------------------------------- */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "error.h"
#include "parse.h"
#include "syn_cam.h"
#if (defined(_HEMI_CUBE) || defined(_CUBIC_TETRA))
#include "prog_rad.h"
#elif defined(_RAY_CAST)
#include "ray_rad.h"
#else
#include "rad_eqn.h"
#endif
#include <proto/intuition.h>
#include <proto/exec.h>
#include <libraries/mui.h>
#include <proto/muimaster.h>
#include "MUIpreview.h"
#include "CalcSub.h"
/* ------------------------------ Definitions ------------------------------- */
#define PROGRAM "AmHelios"
/* --------------------------------- Macros --------------------------------- */
/* -------------------------------- Typedefs -------------------------------- */
/* ------------------------------ Proto Types ------------------------------- */
ULONG iget(APTR obj,Tag attr);
void set(APTR obj,Tag attr,ULONG v);
int main( int argc, char **argv );
void Quit(char *str);
void OpenLibraries(void);
void CloseLibraries(void);
void OpenDisplay(void);
void CloseDisplay(void);
void MainWait(void);
void GetWorld(char *file,char *dir);
__saveds void Render(void);
/* -------------------------------- Structs --------------------------------- */
/* -------------------------------- Globals --------------------------------- */
static Parse Parser; // World file parser
static Environ Environment; // Environment
static SynCamera PreviewCamera(256, 256, -180.0, 90.0, 0.0, 0.0);
static SynCamera RenderCamera(704, 564, -180.0, 90.0, 0.0, 0.0);
static WinBitmap Bitmap;
// Radiosity equation solver
#if (defined(_HEMI_CUBE) || defined(_CUBIC_TETRA))
static ProgRad Radiosity; // Progressive radiosity
#elif defined(_RAY_CAST)
static RayRad Radiosity; // Ray cast radiosity
#else
static RadEqnSolve Radiosity; // Dummy equation solver
#endif
// MUI bits
struct Library *MUIMasterBase = NULL;
APTR my_app;
APTR my_window;
APTR mui_x, mui_y, mui_z, mui_eye, mui_focus;
APTR mui_detail;
APTR mui_render;
APTR mui_preview;
CalcSub *calcsub;
/* ---------------------------------- Code ---------------------------------- */
ULONG iget(APTR obj,Tag attr)
{
ULONG v;
GetAttr(attr,obj,&v);
return v;
}
void set(APTR obj,Tag attr,ULONG v)
{
SetAttrs(obj,attr,v,TAG_DONE);
}
int main( int argc, char **argv )
{
srand((unsigned) time(NULL));
GetWorld(argc > 1 ? argv[1] : "demo/room.wld", argc > 2 ? argv[2] : "demo");
OpenLibraries();
OpenDisplay();
MainWait();
Quit(NULL);
return 0;
}
void Quit(char *str)
{
// Report the error message (if any)
if(str!=NULL)
printf(PROGRAM" Error: %s!\n",str);
CloseDisplay();
CloseLibraries();
exit(0);
}
void OpenLibraries(void)
{
MUIMasterBase = OpenLibrary((TEXT *)"muimaster.library",0L);
if(!MUIMasterBase)
Quit("Couldn't open muimaster.library");
}
void CloseLibraries(void)
{
if(MUIMasterBase) CloseLibrary(MUIMasterBase);
MUIMasterBase = NULL;
}
void OpenDisplay(void)
{
static struct Hook RenderHook={ {NULL,NULL},(__stdargs ULONG (*)())Render,NULL,NULL };
static const char *CYA_Detail[] = { "Global box", "Object boxes", "Full wireframe", NULL };
if(!InitPreviewClass())
Quit("Couldn't create custom MUI class Preview");
my_app = ApplicationObject,
MUIA_Application_Title, "AmHelios",
MUIA_Application_Author, "Jarno van der Linden",
MUIA_Application_Base, "AMHELIOS",
MUIA_Application_Copyright, "Jarno van der Linden",
MUIA_Application_Description, "Radiosity renderer based on Helios",
MUIA_Application_Version, "$VER: AmHelios 0.1 (2.8.97)",
SubWindow, my_window = WindowObject,
MUIA_Window_Title, "AmHelios",
MUIA_Window_ID, 10,
WindowContents, HGroup,
Child, VGroup,
Child, ColGroup(2),
Child, KeyLabel2("X:",'x'), Child, mui_x = KeyCheckMark(TRUE,'x'),
Child, KeyLabel2("Y:",'y'), Child, mui_y = KeyCheckMark(TRUE,'y'),
Child, KeyLabel2("Z:",'z'), Child, mui_z = KeyCheckMark(FALSE,'z'),
Child, KeyLabel2("Eye:",'e'), Child, mui_eye = KeyCheckMark(TRUE,'e'),
Child, KeyLabel2("Focus:",'f'), Child, mui_focus = KeyCheckMark(FALSE,'f'),
Child, KeyLabel2("Detail:",'d'), Child, mui_detail = KeyCycle(CYA_Detail, 'd'),
End,
End,
Child, mui_preview = MUIPreview(&Environment,&PreviewCamera),
MUIA_Preview_Mode, PREVIEW_MOVEEYE | PREVIEW_MOVEX | PREVIEW_MOVEY,
MUIA_Preview_Level, 0,
TextFrame,
End,
Child, VGroup,
Child, mui_render = KeyButton("Render",'r'),
End,
End,
End,
End;
if(!my_app)
Quit("Couldn't create application");
DoMethod((Object *)mui_x,MUIM_Notify,MUIA_Selected,MUIV_EveryTime,
mui_preview,3,MUIM_Set,MUIA_Preview_Mode_Toggle,PREVIEW_MOVEX);
DoMethod((Object *)mui_y,MUIM_Notify,MUIA_Selected,MUIV_EveryTime,
mui_preview,3,MUIM_Set,MUIA_Preview_Mode_Toggle,PREVIEW_MOVEY);
DoMethod((Object *)mui_z,MUIM_Notify,MUIA_Selected,MUIV_EveryTime,
mui_preview,3,MUIM_Set,MUIA_Preview_Mode_Toggle,PREVIEW_MOVEZ);
DoMethod((Object *)mui_eye,MUIM_Notify,MUIA_Selected,MUIV_EveryTime,
mui_preview,3,MUIM_Set,MUIA_Preview_Mode_Toggle,PREVIEW_MOVEEYE);
DoMethod((Object *)mui_focus,MUIM_Notify,MUIA_Selected,MUIV_EveryTime,
mui_preview,3,MUIM_Set,MUIA_Preview_Mode_Toggle,PREVIEW_MOVEFOCUS);
DoMethod((Object *)mui_detail,MUIM_Notify,MUIA_Cycle_Active,MUIV_EveryTime,
mui_preview,3,MUIM_Set,MUIA_Preview_Level,MUIV_TriggerValue);
DoMethod((Object *)mui_render,MUIM_Notify,MUIA_Pressed,FALSE,
mui_render,2,MUIM_CallHook,&RenderHook);
DoMethod((Object *)my_window,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,
my_app,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
set(my_window,MUIA_Window_Open,TRUE);
}
void CloseDisplay(void)
{
if(my_app) MUI_DisposeObject((Object *)my_app);
my_app = NULL;
DeletePreviewClass();
}
void MainWait(void)
{
ULONG sigs = 0;
if (Radiosity.GetStatus() == FALSE)
{
OutOfMemory();
return;
}
Radiosity.SetStopCriterion(0.01);
Radiosity.SetMaxStep(INT_MAX);
Radiosity.EnableAmbient();
calcsub = new CalcSub("CalcSub",&Radiosity,&Environment);
calcsub->Start();
while(DoMethod((Object *)my_app,MUIM_Application_NewInput,&sigs) != MUIV_Application_ReturnID_Quit)
{
if(sigs)
{
sigs = Wait(sigs | SIGBREAKF_CTRL_C);
if(sigs & SIGBREAKF_CTRL_C)
break;
}
printf("%d %lf %s\n", Radiosity.GetStepCount(),
Radiosity.GetConvergence(),
Radiosity.GetElapsedTime());
}
delete calcsub;
}
void GetWorld(char *file,char *dir)
{
if(Parser.ParseFile(file, dir, &Environment) == FALSE)
Quit("Failed to parse input file");
PreviewCamera.InitViewSystem(&Environment);
RenderCamera.InitViewSystem(&Environment);
}
void Render(void)
{
PreviewCamera.CopyViewSys(RenderCamera);
if(Bitmap.Open(RenderCamera.GetWidth(), RenderCamera.GetHeight()) == TRUE)
{
BOOL repeat;
calcsub->Snapshot();
do {
RenderCamera.Shoot(&Environment, &Bitmap, &repeat);
} while(repeat == TRUE);
Bitmap.Write("T:amhelios.iff24");
}
Bitmap.Close();
}